package com.ebs.md.api.orderbook;

/**
 * Revision Author:
 *  $File: //depot/MarketData/commons-md-api/MAIN/src/main/java/com/ebs/md/api/orderbook/BookEntryPositionOfDeleted.java $
 *  $Revision: #3 $
 *  $DateTime: 2012/07/25 10:22:54 $
 *  $Change: 112589 $
 *  $Author: Arik.Sher $
 */

import java.io.Serializable;


public class BookEntryPositionOfDeleted
implements Serializable
{
	// gened by Eclipse
	private static final long serialVersionUID = 2812970131750518860L;

	// Note: the related data is pre(!!!) removal.
	// position 1 is the top position. 2 is the second best and so.
	private int           position;
	// count of entries at this position (including this)
	private int           entriesAtPosition;
	private int           numberOfPositions;
	
	public BookEntryPositionOfDeleted(int position, int entriesAtPosition, int numberOfPositions) {
		super();
		if ( numberOfPositions <= 0 ) {
			throw new IllegalArgumentException(String.format("expecting that numberOfPositions will be positive. value is '%d'", numberOfPositions));
		}
		if ( position <= 0 ) {
			throw new IllegalArgumentException(String.format("expecting that position will be positive. value is '%d'", position));
		}
		if ( entriesAtPosition < 0 ) {
			throw new IllegalArgumentException(String.format("expecting that entriesAtPosition will not be negative. value is '%d'", entriesAtPosition));
		}
		if ( position > numberOfPositions ) {
			throw new IllegalArgumentException(String.format("expecting that position will not be greater than numberOfPositions. numberOfPositions='%d', position='%d'.", numberOfPositions, position));
		}
		this.position = position;
		this.entriesAtPosition = entriesAtPosition;
		this.numberOfPositions = numberOfPositions;
	}
	
	public int getPosition() {
		return position;
	}
	public int getEntriesAtPosition() {
		return entriesAtPosition;
	}
	public int getNumberOfPositions() {
		return numberOfPositions;
	}

	public boolean isPositionEmptyAfterRemoval() {
		return entriesAtPosition == 1;
	}
	
	public boolean isTOBchange() {
		return isTop() && isPositionEmptyAfterRemoval();
	}
	
	public boolean isTop() {
		return position == 1;
	}
	
	public boolean isBottom() {
		return (position == numberOfPositions && !isTop() );
	}
	
	public boolean isMiddle() {
		return (!isTop() && !isBottom() );
	}
	
	public int getDistanceFromTop() {
		return position - 1;
	}
	
	public int getDistanceFromBottom() {
		return numberOfPositions - position;
	}
	
	public int getNumberOfPositionsAfterRemoval() {
		if ( isPositionEmptyAfterRemoval() ) {
			return numberOfPositions - 1;
		} else {
			return numberOfPositions;
		}
	}
	

	
}
